package com.example.mongodb.pojo;

import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.util.Collection;
import java.util.LinkedHashSet;

/**
 * @author ljw
 * @description
 * @date 2022/8/1 7:53
 */
@Setter
@Getter
@Document //注解映射领域模型和 MongoDB 的文档
public class Person {

    @Id
    private String id;
    private String name;
    private Integer age;

    //注解此属性在文档中的名称为locs, locations 属性将以数组形式存在当前数据记录中
    @Field("locs")
    private Collection<Location> locations = new LinkedHashSet<>();

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }
}
